<div class="setting" style="position: relative; top: 140px;">
  <table class="table table-bordered table-stripped" >
    <tr>
      <th style="line-height: 40px; font-size: 18px;">蔚来值区间</th>
      <th style="line-height: 40px; font-size: 18px;">中奖概率</th>
      <th style="line-height: 40px; font-size: 18px;">报名门票数量</th>
      <th style="line-height: 40px; font-size: 18px;">抽取门票数量</th>
      <th style="line-height: 40px; font-size: 18px;"></th>
    </tr>
    <% @settings.each do |setting| %>
      <tr>
        <td style="line-height: 40px;"><%= text_field_tag 'type_name', setting.type_name, "data-setting-id"=> setting.id, class: 'setting_type_name', style: 'width: 120px; border: none;text-align: center;' %></td>
        <td style="line-height: 40px;"><%= text_field_tag 'probability', setting.probability, "data-setting-id"=> setting.id, class: 'setting_probability', style: 'width: 120px; border: none;text-align: center;' %></td>
        <td style="line-height: 40px;"><%= User.where(user_type: setting.id).pluck(:user_count).map(&:to_i).reduce(:+) %></td>
        <td style="line-height: 40px;"><%= text_field_tag 'type_sum', setting.type_sum, class: 'type_sum', style: 'text-align: center;', "data-setting-id"=> setting.id %> 张</td>
        <td style="line-height: 40px;">
          <% if setting.is_done? %>
            <%= link_to '抽取结束', '', "data-setting-id"=> setting.id , class: 'btn btn-success', style: 'background: #e68354;', disabled: true%>
          <% else %>
            <%= link_to '开始抽取', pick_lucky_luckies_path(type_id: setting.id), class: 'btn btn-success', style: 'background: #e68354;' %>
          <% end %>
        </td>
      </tr>
    <% end %>
  </table>

  <%= link_to '返回首页', root_path %>

</div>


<script type="text/javascript">
  $('.setting_type_name').blur(function(){
    var type_id = $(this).data('setting-id');
    var value = $(this).val();
    $.ajax({
      url: '/luckies/update_setting_info',
      type: 'post',
      data: {type_id: type_id, value: value, attr_name: 'type_name'},
      success: function(){}
    })
  });
  $('.setting_probability').blur(function(){
    var type_id = $(this).data('setting-id');
    var value = $(this).val();
    $.ajax({
      url: '/luckies/update_setting_info',
      type: 'post',
      data: {type_id: type_id, value: value, attr_name: 'probability'},
      success: function(){}
    })
  });
  $('.type_sum').blur(function(){
    var type_id = $(this).data('setting-id');
    var value = $(this).val();
    $.ajax({
      url: '/luckies/update_setting_info',
      type: 'post',
      data: {type_id: type_id, value: value, attr_name: 'type_sum'},
      success: function(){}
    })
  });
</script>
